import { applyMiddleware, compose, createStore,combineReducers } from 'redux'
import { routerMiddleware,routerReducer } from 'react-router-redux'
import thunk from 'redux-thunk'
import * as reducers from '../reducers/index'


export default (initialState = {}, history) => {
    // 中间件
    const middleware = [thunk, routerMiddleware(history)]

    const rootReducer = combineReducers({
        ...reducers,
        routing: routerReducer
    })

    // 实例化
    const store = createStore(
        rootReducer,
        initialState,
        compose(
            applyMiddleware(...middleware)
        )
    )

    return store
}

// export default const store = createStore(
//     rootReducer,
//     applyMiddleware(thunk)
// )
